//
//  LPCustomClassObjTools.m
//  ZhongWangYuanApp
//
//  Created by liuyingping on 2018/12/17.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "LPCustomClassObjTools.h"
#import "YBProjectDetailViewController.h"
@implementation LPCustomClassObjTools
+ (void)classApplyWithClassid:(LPZWYChooseClassClassModel *)model Success:(ApplyBlock)successBlock{
    /**  判断是否报名  */
    if ([model.isMyClassPage integerValue] == 1) {
        YBProjectDetailViewController * zjVideoVC = [[YBProjectDetailViewController alloc]init];
        zjVideoVC.theModel = model;
        [[ToolClass getMainNavigationController] pushViewController:zjVideoVC animated:YES];
        return;
    }
    else{
        if ([model.ifsignup integerValue] == 1) {
            YBProjectDetailViewController * zjVideoVC = [[YBProjectDetailViewController alloc]init];
            zjVideoVC.theModel = model;
            [[ToolClass getMainNavigationController] pushViewController:zjVideoVC animated:YES];
            return;
        }
    }
    /**  判断报名时间是否到  */
    if ([model.ishows integerValue] == 0) {
        [YJProgressHUD showSuccess:@"该班级当前不在报名时间范围内!" inview:[UIApplication sharedApplication].keyWindow];
        return;
    }
    
    if ([model.appmainstatus integerValue] == 0) {
         [YJProgressHUD showSuccess:@"报名审核中，请等待审核结果" inview:[UIApplication sharedApplication].keyWindow];
        return;
    }
    
    UIAlertController * alertVC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"是否报名该专题班？" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [YJProgressHUD show:@"报名中..." inView:[UIApplication sharedApplication].keyWindow mode:YJProgressModeLoading];
        [YBRequestManager request_objectSignInWithIdString:model.ID successBlock:^(id object) {
            [YJProgressHUD hide];
            if ([object[@"code"] integerValue] == 1) {
                successBlock(object);
            }
            else{
                [YJProgressHUD showMsgWithoutView:[NSString stringWithFormat:@"%@",object[@"message"]]];
            }
        } failBlock:^(id object) {
            [YJProgressHUD hide];
            [YJProgressHUD showMsgWithoutView:@"报名失败"];
        }];
    }];
    
    UIAlertAction * cannelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertVC addAction:sureAction];
    [alertVC addAction:cannelAction];
    [[ToolClass getMainNavigationController] presentViewController:alertVC animated:YES completion:^{
        
    }];
    
}
@end
